package com.tdmh.test;

/**
 * @author : leimingchao
 * @Description:
 * @date Date : 2021年06月09日 17:34
 */
public class CashCode {
    public static void main(String[] args) {
        String st1 = createBigSmallLetterStrOrNumberRandom(8);
        String st2 = createSmallStrOrNumberRandom(8);
        String st3 = createBigStrOrNumberRandom(8);
        System.out.println(st1);
        System.out.println(st2);
        System.out.println(st3);
    }

    /**
     * 生成num位的随机字符串(数字、大小写字母随机混排)
     */
    public static String createBigSmallLetterStrOrNumberRandom(int num) {

        StringBuilder str = new StringBuilder();
        for (int i = 0; i < num; i++) {
            int intVal = (int) (Math.random() * 58 + 65);
            if (intVal >= 91 && intVal <= 96) {
                i--;
            }
            if (intVal < 91 || intVal > 96) {
                if (intVal % 2 == 0) {
                    str.append((char) intVal);
                } else {
                    str.append((int) (Math.random() * 10));
                }
            }
        }
        return str.toString();
    }

    /**
     * 生成num位的随机字符串(数字、小写字母随机混排)
     */
    public static String createSmallStrOrNumberRandom(int num) {

        StringBuilder str = new StringBuilder();
        for (int i = 0; i < num; i++) {
            int intVal = (int) (Math.random() * 26 + 97);
            if (intVal % 2 == 0) {
                str.append((char) intVal);
            } else {
                str.append((int) (Math.random() * 10));
            }
        }
        return str.toString();
    }

    /**
     * 生成num位的随机字符串(大写字母与数字混排)
     */
    public static String createBigStrOrNumberRandom(int num) {

        StringBuilder str = new StringBuilder();
        for (int i = 0; i < num; i++) {
            // int intVal = (int) (Math.random() * 26 + 65);
            // if (intVal % 2 == 0) {
            //     str.append((char) intVal);
            // } else {
            //     str.append((int) (Math.random() * 10));
            // }
            str.append((int) (Math.random() * 10));
        }
        return str.toString();
    }
}
